package opengl.program;


public class BaseGLProgram extends GLProgram {

	protected final static String BASE_VERT_SHADER_FILE_NAME = "..\\shader\\baseVert.glsl";
	protected final static String BASE_FRAG_SHADER_FILE_NAME = "..\\shader\\baseFrag.glsl";

	protected final static String PROJECTION_MATRIX_NAME = "projectionMatrix";

	protected final static String TEXTURE_NAME = "texture";

	protected final static String INPUT_POSITION_NAME = "inPosition";
	protected final static String INPUT_COLOR_NAME = "inColor";
	protected final static String INNUT_TEXTURECOORD_NAME = "inTextureCoord";

	// vertex shader
	protected int projectionMatrixUniform;

	// fragment shader
	protected int textureUniform;

	protected int positionIndex;
	protected int colorIndex;
	protected int textureCoordIndex;

	public BaseGLProgram() {
		super();
	}

	public void init() throws Exception {
		initShaders();
		getUniformLocations();
		getAttribLocationes();
	}

	protected void initShaders() throws Exception {
		int vs = GLShader.createVertexShader(this, BASE_VERT_SHADER_FILE_NAME);
		int fs = GLShader.createFragmentShader(this, BASE_FRAG_SHADER_FILE_NAME);
		super.initShaders(vs, fs);
	}

	protected void getUniformLocations() {
		projectionMatrixUniform = getUniformLocation(PROJECTION_MATRIX_NAME);
		textureUniform = getUniformLocation(TEXTURE_NAME);
	}

	protected void getAttribLocationes() {
		positionIndex = getAttribLocation(INPUT_POSITION_NAME);
		colorIndex = getAttribLocation(INPUT_COLOR_NAME);
		textureCoordIndex = getAttribLocation(INNUT_TEXTURECOORD_NAME);
	}

	public int getProjectionMatrixUniform() {
		return projectionMatrixUniform;
	}

	public int getTextureUniform() {
		return textureUniform;
	}

	public int getPositionIndex() {
		return positionIndex;
	}

	public int getColorIndex() {
		return colorIndex;
	}

	public int getTextureCoordIndex() {
		return textureCoordIndex;
	}
}